/**
 * 
 */
package edu.umd.clip.lm.model.data;

import java.io.IOException;
import java.util.*;

/**
 * @author Denis Filimonov <den@cs.umd.edu>
 *
 */
public abstract class TrainingDataNodeReader {
	protected FinishedReadingObservable finishedReadingNode;
	
	protected TrainingDataNodeReader() {
		finishedReadingNode = new FinishedReadingObservable();
	}
	
	private static class FinishedReadingObservable extends Observable {
		public void finished() {
			setChanged();
		}
	}

	public abstract ReadableTrainingDataNode getNext();
	
	public abstract void close() throws IOException;
	
	//public abstract boolean canReset();

	//public abstract void reset() throws IOException;
	
	//public abstract void skipCurrentNode() throws IOException;
	
	public void addFinishedReadingNodeObserver(Observer o) {
		finishedReadingNode.addObserver(o);
	}
	
	public void deleteFinishedReadingNodeObserver(Observer o) {
		finishedReadingNode.deleteObserver(o);
	}
	
	protected void finishedReadingNode(ReadableTrainingDataNode node) {
		//System.err.printf("finishedReading node #%d\n", node.getNodeId());
		finishedReadingNode.finished();
		finishedReadingNode.notifyObservers(node);
	}
}
